package homework.handler.highstakes;

import com.sun.net.httpserver.HttpExchange;
import homework.RequestMethod;
import homework.Resource;
import homework.handler.AbstractRequestHandler;
import homework.manager.StakeManager;

import java.io.IOException;

@RequestMethod("GET")
public class HighStakeHandler extends AbstractRequestHandler<HighStackRequest> {
    @Resource
    private StakeManager stakeManager;

    @Override
    public HighStackRequest parse(HttpExchange exchange, String[] paths) {
        boolean match = paths.length > 2 && paths[2].equals("highstakes");
        if(match) {
            HighStackRequest stakeRequest = new HighStackRequest();
            stakeRequest.setBetOfferId(paths[1]);
            return stakeRequest;
        }
        return null;
    }

    @Override
    public void handle(HttpExchange exchange, HighStackRequest request) throws IOException {
        String highStakes = stakeManager.getHighStakes(request.getBetOfferId());
        response(exchange, highStakes);
    }
}
